import torch
from flask import jsonify


def jsonToTensor(data):
    """将json数据转换为tensor"""
    segment_data = data.to_numpy().reshape(1, 7, 3000)
    segment_tensor = torch.tensor(
        segment_data, dtype=torch.float32)
    return segment_tensor

def result(predicted):
    '''根据预测结果返回对应的报告'''
    REPORT = {'wakefulness': 1, 'light_sleep': 2, 'deep_sleep': 3, 'REM': 4, }

    json_data = {"type": predicted, "report": str(REPORT.get(predicted))}
    return jsonify(json_data)
